package com.ssh.xml.action;

import java.util.ArrayList;
import java.util.List;

import com.ssh.web.common.BaseAction;
import com.ssh.xml.bean.AutoModel;
import com.ssh.xml.util.XMLUtil;

public class AutoModelAction extends BaseAction {
	private static final long serialVersionUID = -1502112370121099011L;
	private static List<AutoModel> model_list = null;

	public String showAutoModel() {
		String[] fileNames = {
				XMLUtil.LOCAL_PATH + "auto_model_schema_1.xml",
				XMLUtil.LOCAL_PATH + "auto_model_schema_2.xml"
		};
		List<AutoModel> list = XMLUtil.getAutoModelList(fileNames);

		if (model_list == null) {
			list = XMLUtil.getAutoModelList(fileNames);
			model_list = new ArrayList<AutoModel>(list);
		} else {
			list = new ArrayList<AutoModel>(model_list);
		}

		setPageInfo(list, PAGESIZE);

		int begin = (pageNo -1 ) * PAGESIZE;
		int end = (pageNo * PAGESIZE - 1) > list.size() ? list.size() : (pageNo * PAGESIZE - 1);
		getRequest().setAttribute("autoModelList", list.subList(begin, end));

		currentPage = pageNo;

		getRequest().setAttribute("currentPage", currentPage);
		getRequest().setAttribute("pageNo", pageNo);
		return "show";
	}

}
